package com.shhm.admin.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.PageDTO;
import com.shhm.admin.mapper.RoleMenuMapper;
import com.shhm.admin.service.RoleMenuService;
import com.shhm.admin.util.RequestUtil;
import com.shhm.common.dto.request.RequestList;
import com.shhm.common.dto.response.AjaxResultPlus;
import com.shhm.common.dto.response.admin.SysRoleMenuVO;
import com.shhm.common.dto.response.admin.SysRoleOperatePermsVO;
import com.shhm.common.mapper.SysRoleOperatePermsMapper;
import com.shhm.common.utils.ResponseUtil;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author JackZ
 * @version 1.0
 * @description: TODO
 * @date 2025/8/16 下午2:48
 */
@Service
public class RoleMenuServiceImpl implements RoleMenuService {
    @Resource
    private RoleMenuMapper roleMenuMapper;
    @Resource
    private SysRoleOperatePermsMapper sysRoleOperatePermsMapper;

    @Override
    public AjaxResultPlus pageList(Integer pageNum, Integer pageSize, HttpServletRequest request) {
        PageDTO<SysRoleMenuVO> defPage = new PageDTO<>(pageNum, pageSize);
        PageDTO<SysRoleMenuVO> list = roleMenuMapper.pageList(defPage);
        String userOperatePerms = RequestUtil.getUserOperatePerms(request, sysRoleOperatePermsMapper);
//        if (userOperatePerms.equals("NOT_PERMISSION")) return AjaxResultPlus.error(403,"您无权查看数据");
        return AjaxResultPlus.custom(200, false)
                .put("data",list)
                .put("operateStr",userOperatePerms);
    }

    @Override
    public AjaxResultPlus pageSearchList(Integer pageNum, Integer pageSize, SysRoleMenuVO entity) {
        PageDTO<SysRoleOperatePermsVO> defPage = new PageDTO<>(pageNum, pageSize);
        return AjaxResultPlus.success(roleMenuMapper.pageSearchList(defPage,entity),false);
    }

    @Override
    public AjaxResultPlus add(SysRoleMenuVO entity) {
        return ResponseUtil.sqlExeIsSuccess(roleMenuMapper.insert(entity));
    }

    @Override
    public AjaxResultPlus update(SysRoleMenuVO entity) {
//        entity.setRoleId((long)entity.getVersion()+1);
        return ResponseUtil.sqlExeIsSuccess(roleMenuMapper.updateById(entity));
    }

    @Override
    public AjaxResultPlus delete(RequestList ids) {
        List<Object> list = ids.getList();
        return ResponseUtil.sqlExeIsSuccess(roleMenuMapper.deleteByIds(list));
    }
}
